;
(function() {
	var role = require("./role");
	var db = require("../../core/db/index");
	var config = require("../../core/_include/config");
	var AdminCon = require("../../core/admin/_con");
	var DotnarCaseCon = require("../../core/dotnar_case/_con");
	var ResponObj = require("../_include/responObj");
	module.exports = {
		prefix: "/case",
		get: {
			"/byId": function() {
				var query = this.query;
				var case_id = query.case_id;
				if (!case_id) {
					throwCusError("参数错误")
				}
				var dotnar_case = DotnarCaseCon.get(case_id);
				if (!dotnar_case) {
					throwCusError("找不到指定案例")
				}
				this.body = ResponObj("json", dotnar_case);
			},
			"/list": function() {
				var query = this.query;
				var dotnar_case_list = DotnarCaseCon.getAll(query.num, query.page);
				this.body = ResponObj("json", dotnar_case_list);
			},
		},
		post: {
			"/add_case": function() {
				var case_info = this.request.body;
				var admin = role.getAdmin(this);
				var case_id = admin.addCase(case_info);
				this.body = ResponObj("json", DotnarCaseCon.get(case_id));
			},
		},
		put: {
			"/update_case": function() {
				var dotnar_case = this.request.body;
				var case_id = dotnar_case.case_id;
				var case_info = dotnar_case.info;
				if (!(case_id && case_info)) {
					throwCusError("参数错误");
				}
				var admin = role.getAdmin(this);
				admin.updateCase(case_id, case_info);
				this.body = ResponObj("json", DotnarCaseCon.get(case_id));
			}
		},
		"delete": {
			"/remove_case": function() {
				var body = this.request.body;
				var case_id = body.case_id;
				if (!case_id) {
					throwCusError("参数错误")
				}
				var admin = role.getAdmin(this);
				admin.removeCase(case_id);
				return module.exports.get["/list"].apply(this, arguments);
			},
		}
	}
}());